package com.hk.service.impl;

import org.springframework.stereotype.Service;

import com.hk.commons.HqlFilter;
import com.hk.commons.StringHelper;
import com.hk.commons.entity.Bank;
import com.hk.dao.base.impl.BaseServiceImpl;
import com.hk.service.sys.IBank;

@Service
public class BankImpl extends BaseServiceImpl<Bank> implements IBank {

	@Override
	public Bank findById(Integer id) {
		return getById(id);
	}

	@Override
	public void add(Bank model) {

		super.save(model);
	}

	@Override
	public Bank delete(Integer id) {
		Bank model = new Bank();
		model.setId(id);
		delete(model);
		return model;
	}

	@Override
	public Boolean existById(Integer bankId) {

		Bank bank = getById(bankId);
		return bank != null;
	}

	@Override
	public String getBankNameById(Integer bankId) {
		String bankName = "";
		Bank bank = getById(bankId);
		if (bank != null) {
			bankName = bank.getBankName();
		}
		return bankName;
	}

	@Override
	public Integer getBankIdByCode(String bankCode) {

		Integer bankId = null;
		if (StringHelper.isNotEmpty(bankCode)) {
			HqlFilter hqlFilter = new HqlFilter();
			hqlFilter.addEQFilter("bankCode", bankCode);

			Bank bank = getByFilter(hqlFilter);
			if (bank != null) {
				bankId = bank.getId();
			}
		}
		return bankId;
	}
}
